<template>
	<hearder ></hearder>
	<view class="content">
		<image style="width: 100%;height: 1000rpx;"
			src="http://www.html5-app.com/file/1.docx" mode="">
		</image>
		
		<view class="way" @click="editorUrlnDoc()">远程文档编辑</view>
		<view class="way" @click="loactionFilDoc()">本地文档编辑</view>
		<view class="way" @click="scanDocInfo()">文档预览</view>
	</view>
</template>

<script>
	import hearder from '../../components/header_back/header_back.vue'
	// #ifdef APP-PLUS
	const wpsTool=uni.requireNativePlugin("CL-WPSTool");
	// #endif
	// #ifdef MP-WEIXIN
	const wpsTool = ""
	// #endif
	export default {
		components: {
			hearder
		},
		data() {
			return {
				title: '',
				filePath:'',
			};
		},
		onLoad(option) {
			this.title = option.title
			uni.setNavigationBarTitle({
				title: option.title
			})
		},
		methods:{
			// 本地文档编辑
			loactionFilDoc:function(){
				
				
				let filePath=plus.io.convertLocalFileSystemURL("_doc/uniapp_temp_1700192163749/download/1(1).docx");
				
				this.openDocInfo(filePath,true);
				
				
			},
			//文档预览
			        scanDocInfo:function(){			         //filePath 为绝对路径;
			            wpsTool.wpsOpenFile("_doc/uniapp_temp_1700192163749/download/1(1).docx",result=>{
			                 console.log(result+"aaa");
			            })
			
			        },
			//远程文件下载
				editorUrlnDoc:function(){
				
					if(this.path)
					{
						 this.openDocInfo(this.path,true);	
						return ;
					}
					
					uni.showLoading({
						title:"稍后.."
					})
			
					uni.downloadFile({
						url:"http://www.html5-app.com/file/1.docx",
						success:(res)=>{
						
							uni.hideLoading()
							uni.showModal({
								 content:JSON.stringify(res)
							})
						    console.log(res);
						    if (res.statusCode === 200) {
						       
								const{tempFilePath}=res;	
							    let filePath=plus.io.convertLocalFileSystemURL(tempFilePath);  		 
							    this.openDocInfo(filePath,true);							
						    }	
									
					   },
						fail: (e) => {
							uni.hideLoading()
							 console.log(e);
							 uni.showModal({
							 	content:JSON.stringify(e)+"失败"
							 })
						}
							
				  })
							
				},
				// 远程文档编辑
				openDocInfo:function(filePath,isEditor){
					
					if(!isEditor)
					{	
					
						wpsTool.wpsOpenFile(filePath,result=>{
							
							 console.log(result+"aaa");
						})	
				
					}
					else
					{
						
						let options={
							filePath:"http://www.html5-app.com/file/1.docx",//文件路径 必填
							userName:"212请问",//必填，用于记录编辑信息
							isEnterReviseMode:true //是否进入修订模式,默认true
						};	
						console.log("开始编辑");
						wpsTool.wpsEditorFile(options,result=>{
							
							 console.log(result);
							 const{code,msg}=result; 
							 if(code==1)
							 {
								  //成功;
								 let newPath=result.path;//该路径为绝对路径;
								 this.path=newPath;
																					
							 }
							 else
							 {
							 	//失败情况;
							 							 
							 }
						})						
					}
					
				},
				
			}
		}
	
</script>

<style lang="scss">
	.content {
		width: 85%;
		margin: auto;
		margin-top: 40rpx;

	}

	.add {
		position: relative;
		top: -20rpx;

	}
	.way{
		height: 80rpx;
		background-color: #007AFF;
		color: white;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 30rpx;
	}
	
</style>